home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6982 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.2 KB  |  68 lines

  1. Path: ntc.nokia.com!usenet
  2. From: Hannu Kaikkonen <hannu.kaikkonen@ntc.nokia.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Screenprinting problem!
  5. Date: Wed, 21 Feb 1996 11:34:03 +0200
  6. Organization: Nokia Telecommunications Oy
  7. Message-ID: <312AE70B.4EEB@ntc.nokia.com>
  8. NNTP-Posting-Host: pc-hkaikkonen.ntc.nokia.com
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=iso-8859-1
  11. Content-Transfer-Encoding: 8bit
  12. X-Mailer: Mozilla 2.0 (WinNT; I)
  13.  
  14. I am making a program that reads characters from a com port.  I can successfully get 
  15. the characters to my hard disk. I can also use the EvChar and Paint functions to type 
  16. key strokes to screen. What do I need to do to get characters from the com port to 
  17. appear on the screen?? I guess I need to tell somehow to the windows to repaint the 
  18. screen. My program is a modified example of the book teach yourself borland C++ 4.0 in 
  19. 21 days (listing 14.5 Real.cpp). The idea of the program code is something like this 
  20. (lot of stuff missing):
  21.  
  22. class Alarms : public TWindow
  23. {
  24. protected:
  25.     int currentLine;            // line being typed in now
  26.     int lineLen[maxLines];        // length of each line
  27.     char *linePtrs[maxLines];        // string for each line
  28.     BOOL isMinimized;        // TRUE if window is an icon
  29.     TSize windowSize;        // structure with size pixels
  30.     void Paint(TDC& dc, BOOL, TRect&);
  31.     void EvSize(UINT sizeType, TSize& size);
  32. }
  33.  
  34. Alarms::MyFunc()
  35. {
  36.  
  37. Stuff needed to read the Com port.  Characters are read to a string buffer.
  38. ReadComm(Com1DCB.Id,Buffer,300)
  39.  
  40.  
  41. }
  42.  
  43. // Called when time to update (paint) the screen
  44. void Alarms::Paint(TDC& dc, BOOL, TRect&)
  45. {
  46.     int lineNum;        // line number to write
  47.     int yPos;            // vertical position on screen
  48.     int displayedLines;    // number of linePtrs in this window
  49.     TSize textSize;        // used to get char height in pixels
  50.     if (isMinimized)        // don┤t write to an icon
  51.         return;
  52.  
  53.     // Get char sizes so that height is saved
  54.     textSize = dc.GetTextExtent("W",1);
  55.     displayedLines = windowSize.cy / textSize.cy;
  56.  
  57.     if (displayedLines > maxLines)
  58.         displayedLines = maxLines;
  59.  
  60.     for (lineNum = yPos = 0; lineNum < displayedLines; ++lineNum)
  61.         {
  62.         if (lineLen[lineNum] > 0)    // if any text on the line
  63.         dc.TextOut(0, yPos, linePtrs[lineNum], lineLen[lineNum]);
  64.  
  65.         yPos += textSize.cy;    // adjust screen line position
  66.         }
  67. }
  68.